package cn.bonoon.kernel.web.handlers.loader;

import java.lang.reflect.Constructor;

public final class StandardQueryParameter implements IQueryParameter{
	private final Class<?> queryClass;
	private Constructor<?> queryConstructor;
	
	public StandardQueryParameter(Class<?> queryClass){
		this.queryClass = queryClass;
	}
	
	public IQueryParameter init(){
		try{
			this.queryConstructor = queryClass.getConstructor();
		}catch(Exception ex){
			//无法使用查询条件
			return EMPTY;
		}
		return this;
	}

	@Override
	public Object instance() {
		try {
			return queryConstructor.newInstance();
		} catch (Exception e) {
			//nothing to do!
			return null;
		}
	}
}
